package com.monkey.web.platform.controller;

import com.monkey.core.domain.icon.Icon;
import com.monkey.core.domain.icon.IconType;
import com.monkey.core.repository.search.Searchable;
import com.monkey.web.platform.service.IconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * Project  : monkey
 * Author   : Wu Tian Qiang
 * Date     : 2016/10/17
 */
@Controller
@RequestMapping(value = "/m", produces = {MediaType.APPLICATION_JSON_VALUE})
public class IconController {

    @Autowired
    private IconService iconService;

    @RequestMapping(value = "/icons", method = RequestMethod.GET)
    public Page<Icon> icons(Searchable searchable) {
        searchable.addSort(Sort.Direction.DESC, "createTime");
        return iconService.findAll(searchable);
    }


    @RequestMapping(value = "/syn_icons", method = RequestMethod.GET)
    public String synIcons(HttpServletRequest request) {
        iconService.synIcons(request);
        return "SUCCESS:同步图标完成";
    }


}
